class Solution {
public:    
    typedef unsigned long long ull;
    unordered_map<int,ull> hash;
    ull dfs(TreeNode* root,int deep,ull index){
        if(!root) return 0;
        
        if(!hash.count(deep)){
            hash[deep] = index;
        }
        
        return max({index - hash[deep] + 1, dfs(root->left,deep+1,index*2+1),dfs(root->right,deep+1,index*2+2)});
        
    }      
                                        
    int widthOfBinaryTree(TreeNode* root) {
        if(!root) return 0;
        
        return dfs(root,0,0);
    }
};

